package com.lib724.dao;

import java.io.IOException;
import java.io.Reader;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class SqlMapClientP implements Provider<SqlMapClient> {
	   
    private static SqlMapClient sqlMapClient;
    @Inject @Named("ibatis.configXml") String configXml;
   
    public SqlMapClient get() {
        if(sqlMapClient != null){
        	return sqlMapClient;
        }
        try {
            Reader reader = Resources.getResourceAsReader(configXml);
            sqlMapClient  = SqlMapClientBuilder.buildSqlMapClient(reader);
            reader.close();
        }catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("SqlMapClientP unable to create instance." + e);
        }
        return sqlMapClient;
    }

}